var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');
var wxcache = require('../../../utils/wxcache.js');
var app = getApp();
Page({
  data: {
    username: '',
    password: '',
    vcode:'',
    seqNo:'',
    confirmPassword: '',
    code: '',
    loginErrorCount: 0
  },
  onLoad: function (options) {
    this.setData({
      username: wxcache.get("phoneNumber")
        })
     
    wx.showToast({
      title: '请设置密码',
      icon: 'succes',
      duration: 2000,
      mask: true
    })
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  startRegister: function () {

    var that = this;
    
    if (that.data.password.length < 3 || that.data.username.length < 3) {
      wx.showModal({
        title: '错误信息',
        content: '用户名和密码不得少于3位',
        showCancel: false
      });
      return false;
    }

    if (that.data.password != that.data.confirmPassword) {
      wx.showModal({
        title: '错误信息',
        content: '确认密码不一致',
        showCancel: false
      });
      return false;
    }
    //调用修改密码接口
    var data = {}
    data.mobile = this.data.username
    data.password = this.data.password
    util.request(api.PasswordUpdate, data, 'POST').then(function (res) {
      console.log(res)
      if (res.code == 200) {
        
        wx.navigateBack({
          delta: 2
        })
        wx.showToast({
          title: '密码设置成功',
          icon: 'succes',
          duration: 2000,
          mask: true
        })
      } else {
        console.log('设置密码失败');
        wx.showModal({
          title: '提示信息',
          content: '系统正在维护，请联系客服，给您造成的不便敬请谅解',
          showCancel: false
        });
        return 
      }
    })
 
  },

  jumpToSelfcenterpage:function(){
    //  wx.switchTab({
    //    url: '/pages/ucenter/index/index',
    //  })
    wx.navigateBack({
      delta: 2
    })
    wx.showToast({
      title: '登陆成功',
      icon: 'succes',
      duration: 2000,
      mask: true
    })
  },

  bindUsernameInput: function (e) {

    this.setData({
      username: e.detail.value
    });
  },
  bindPasswordInput: function (e) {

    this.setData({
      password: e.detail.value
    });
  },
  bindConfirmPasswordInput: function (e) {

    this.setData({
      confirmPassword: e.detail.value
    });
  },
  bindCodeInput: function (e) {

    this.setData({
      code: e.detail.value
    });
  },
  clearInput: function (e) {
    switch (e.currentTarget.id) {
      case 'clear-username':
        this.setData({
          username: ''
        });
        break;
      case 'clear-password':
        this.setData({
          password: ''
        });
        break;
      case 'clear-confirm-password':
        this.setData({
          confirmPassword: ''
        });
        break;
      case 'clear-code':
        this.setData({
          code: ''
        });
        break;
    }
  }
})